package com.senlingspace.web.controller.shop;

import java.util.List;

import com.github.pagehelper.PageInfo;
import com.senlingspace.common.utils.poi.ExcelUtil;
import com.senlingspace.system.domain.SlkjStoreCost;
import com.senlingspace.system.domain.dto.StoreCostDto;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.senlingspace.common.annotation.Log;
import com.senlingspace.common.core.controller.BaseController;
import com.senlingspace.common.core.domain.AjaxResult;
import com.senlingspace.common.enums.BusinessType;
import com.senlingspace.system.service.ISlkjStoreCostService;
import com.senlingspace.common.core.page.TableDataInfo;

import javax.servlet.http.HttpServletResponse;

/**
 * 门店成本上报Controller
 *
 * @author SenlingSpace
 * @date 2024-07-22
 */
@RestController
@RequestMapping("/system/cost")
public class SlkjStoreCostController extends BaseController
{
    @Autowired
    private ISlkjStoreCostService slkjStoreCostService;

    /**
     * 查询门店成本上报列表
     */
    @PreAuthorize("@ss.hasPermi('system:cost:list')")
    @GetMapping("/list")
    public TableDataInfo list(SlkjStoreCost slkjStoreCost,Long deptId) {
        PageInfo<SlkjStoreCost> list = slkjStoreCostService.selectSlkjStoreCostList(slkjStoreCost, deptId, true);
        return getDataTable(list);
    }

   /**
    * 导出门店成本上报列表
    */
   @PreAuthorize("@ss.hasPermi('system:cost:export')")
   @Log(title = "门店成本上报", businessType = BusinessType.EXPORT)
   @PostMapping("/export")
   public void export(HttpServletResponse response, SlkjStoreCost slkjStoreCost,Long shopId) {
       PageInfo<SlkjStoreCost> list = slkjStoreCostService.selectSlkjStoreCostList(slkjStoreCost, shopId, false);
       ExcelUtil<SlkjStoreCost> util = new ExcelUtil<SlkjStoreCost>(SlkjStoreCost.class);
       util.exportExcel(response, list.getList(), "门店成本上报数据");
   }

    /**
     * 获取门店成本上报详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:cost:query')")
    @GetMapping(value = "/{storeId}")
    public AjaxResult getInfo(@PathVariable("storeId") Long storeId)
    {
        return success(slkjStoreCostService.selectStoreCostTdoByStoreId(storeId));
    }

    /**
     * 新增门店成本上报
     */
    @PreAuthorize("@ss.hasPermi('system:cost:add')")
    @Log(title = "门店成本上报", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StoreCostDto costDto)
    {
        return toAjax(slkjStoreCostService.insertSlkjStoreCost(costDto));
    }

    /**
     * 修改门店成本上报
     */
    @PreAuthorize("@ss.hasPermi('system:cost:edit')")
    @Log(title = "门店成本上报", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StoreCostDto costDto)
    {
        return toAjax(slkjStoreCostService.updateSlkjStoreCost(costDto));
    }

    /**
     * 删除门店成本上报
     */
    // @PreAuthorize("@ss.hasPermi('system:cost:remove')")
    // @Log(title = "门店成本上报", businessType = BusinessType.DELETE)
	// @DeleteMapping("/{storeIds}")
    // public AjaxResult remove(@PathVariable Long[] storeIds)
    // {
    //     return toAjax(slkjStoreCostService.deleteSlkjStoreCostByStoreIds(storeIds));
    // }
}
